package cn.cloud.butler.webapi.repository;

import cn.cloud.butler.webapi.domain.ProducePriceEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by zhouguocheng on 2018-12-03-上午 10:31
 */
public interface ProducePriceRepository extends JpaRepository<ProducePriceEntity,Integer> {


    //@Query(value = "SELECT * FROM ProducePrice WHERE ProduceName = ?1 AND Compid = ?2 ",nativeQuery = true)
    List<ProducePriceEntity> findByCompIdAndProduceName(Long compID, String produceName);

    List<ProducePriceEntity> findByCompId(Long compId);
    @Modifying
    @Query(value = "UPDATE ProducePrice SET Price = ?2 WHERE ProduceName= ?1 AND Compid = ?3" ,nativeQuery = true)
    void updateByNameAndCompid(String producename, Float price,Long Compid);

    @Modifying //insert into ProducePrice (CompID, Price, ProduceNameDistinct) values (?, ?, ?)
    @Query(value = "INSERT INTO ProducePrice(CompID,Price,ProduceName) VALUES (?1,?2,?3)",nativeQuery = true)
    void addProductPrice(Integer pid, Float price, String producename);
}
